package com.smh.a03exerciseDemo1;

import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.StringJoiner;

public class Test4 {
    public static void main(String[] args) throws IOException {

        FileReader fr = new FileReader("day26-code\\file\\d.txt");

        FileWriter fw = new FileWriter("day26-code\\file\\e.txt");

        char[] chars = new char[1024 * 1024];
        int len;
        StringBuilder sb = new StringBuilder();
        while ((len = fr.read(chars)) != -1) {
            sb.append(chars, 0, len);
//            for (char aChar : chars) {
//                sb.append(aChar);
//            }
        }
        String[] strArray = sb.toString().split("-");
        ArrayList<Integer> list = new ArrayList<>();
        for (String s : strArray) {
            int i = Integer.parseInt(s);
            list.add(i);
        }
        list.sort((o1, o2) -> o1 - o2);
        StringJoiner sj = new StringJoiner("-");
        for (Integer i : list) {
            sj.add(String.valueOf(i));
        }

        char[] charArray = sj.toString().toCharArray();


//        char[] charArray = sb.toString().toCharArray();
//        Arrays.sort(charArray);

        fw.write(charArray);
        fw.close();
        fr.close();


    }
}
